array-bytes
A Collection of Array/Bytes/Hex Utilities.
Abilities
TryFromHex
trait
- Convert hex to num
- type
AsRef<[u8]> -> isize
- type
AsRef<[u8]> -> i8
- type
AsRef<[u8]> -> i16
- type
AsRef<[u8]> -> i32
- type
AsRef<[u8]> -> i64
- type
AsRef<[u8]> -> i128
- type
AsRef<[u8]> -> usize
- type
AsRef<[u8]> -> u8
- type
AsRef<[u8]> -> u16
- type
AsRef<[u8]> -> u32
- type
AsRef<[u8]> -> u64
- type
AsRef<[u8]> -> u128
- type
- Convert hex to array
- type
AsRef<[u8]> -> [u8; N]
,N = { [1, 64], 128, 256, 512 }
- type
AsRef<[u8]> -> Vec<u8>
- type
Hex
trait
- Convert num to hex
- type
isize -> String
- type
i8 -> String
- type
i16 -> String
- type
i32 -> String
- type
i64 -> String
- type
i128 -> String
- type
usize -> String
- type
u8 -> String
- type
u16 -> String
- type
u32 -> String
- type
u64 -> String
- type
u128 -> String
- type
- Convert array to hex
- type
Vec<u8> -> String
- type
[u8; N] -> String
,N = { [1, 64], 128, 256, 512 }
- type
&[u8] -> String
- type
slice
prefixed functions
- Build fixed length
Array
fromSlice
- type
&[T] -> [T; N]
- type
&[T] -> &[T; N]
- type
- Transform
Slice
toG
- type
&[T] -> G
- e.g.
&[0_u8, ...] -> [u8; 20] -> H160
- type
prefix
and suffix
functions
- Prefixes/suffixes the given element to the given slice to make it a fixed-size array of length
N
.
bytes
prefixed functions
- Convert bytes to hex
- type
AsRef<[u8]> -> String
- type
hex
prefixed functions
- Convert
HexBytes
to hex- type
&[u8] -> &str
- e.g.
b"0x..." -> "0x..."
- type
- Transform hex from
Array
- type
&str -> [u8; N]
- type
- Convert hex to bytes
- type
AsRef<[u8]> -> Vec<u8>
- type
- Convert hex to
Slice
- type
AsRef<[u8]> -> &[u8]
- type
- Transform hex to
T
- type
AsRef<[u8]> -> T
- e.g.
"0x..." -> [u8; 20] -> H160
- type
vec
prefixed functions
- Build fixed length
Array
fromVec
- type
Vec<T> -> [T; N]
- type
- Transform
Vec
toG
- type
Vec<T> -> G
- e.g.
vec![0_u8, ...] -> [u8; 20] -> H160
- type
Serde support (require feature serde
)
#[serde(deserialize_with = "array_bytes::hex_deserialize_n_into")]
- type
S -> T
- e.g.
"0x..." -> H160
- type
#[serde(deserialize_with = "array_bytes::de_hex2num")]
- type
S -> Num
- e.g.
"0xA" -> 10_u32
- type
#[serde(deserialize_with = "array_bytes::de_hex2bytes")]
- type
S -> Vec<u8>
- e.g.
"0x00" -> vec![0_u8]
- type
Benchmark results
:
change:
Performance has improved.
Found 4 outliers among 100 measurements
3 high mild
1 high severe
encode time:
change:
Performance has regressed.
hex_string time:
change:
No change in performance detected.
hex_encode_fallback
time:
change:
No change in performance detected.
Found 1 outliers among 100 measurements
1 high mild
encode time:
change:
No change in performance detected.
Found 15 outliers among 100 measurements
13 low severe
2 low mild
to_hex time:
change:
No change in performance detected.
hex2bytes time:
change:
Performance has improved.
Found 6 outliers among 100 measurements
1 high mild
5 high severe
hex2bytes_unchecked
time:
change:
Change within noise threshold.
Found 17 outliers among 100 measurements
11 low mild
5 high mild
1 high severe
hex2slice time:
change:
Change within noise threshold.
Found 6 outliers among 100 measurements
6 high mild
hex2slice_unchecked
time:
change:
Performance has improved.
Found 13 outliers among 100 measurements
8 high mild
5 high severe
decode time:
change:
Performance has improved.
hex_decode time:
change:
Change within noise threshold.
Found 7 outliers among 100 measurements
5 high mild
2 high severe
hex_decode_unchecked
time:
change:
Change within noise threshold.
Found 10 outliers among 100 measurements
6 high mild
4 high severe
hex_decode_fallback
time:
change:
Performance has improved.
Found 9 outliers among 100 measurements
5 high mild
4 high severe
decode time:
change:
Performance has regressed.
Found 15 outliers among 100 measurements
15 high severe
decode_to_slice time:
change:
Change within noise threshold.
Found 2 outliers among 100 measurements
1 high mild
1 high severe
from_hex time:
change:
Change within noise threshold.
Found 2 outliers among 100 measurements
2 high mild
bytes2hex time
License
Licensed under either of Apache-2.0 or GPL-3.0 at your option.